//
//  TuneFusionAudioObject.m
//  TuneFusion
//
//  Created by Fabián Cañas on 9/10/10.
//  Copyright 2010 University of Colorado, Boulder. All rights reserved.
//

#import "TuneFusionAudioObject.h"
//#include <openssl/md5.h>

@implementation TuneFusionAudioObject

@synthesize isFinishedTranscoding, sourcePath, lastAccess, dataFileLocation, dataFile;

@synthesize total_samples, sample_rate, channels, bps;


-(id) initWithSourcePath:(NSString *)path{
    self = [super init];
    if (self!=nil) {
        
        self.isFinishedTranscoding = FALSE;
        self.sourcePath = path;
        self.lastAccess = [NSDate date];
        
        self.dataFileLocation = [@"TuneFusion_" stringByAppendingString:[[NSNumber numberWithInt:(int)self] stringValue]];
        
        self.dataFileLocation = [NSTemporaryDirectory() stringByAppendingPathComponent:dataFileLocation];
        
        
        NSFileManager *filemgr;
        filemgr = [NSFileManager defaultManager];
        [filemgr createFileAtPath:self.dataFileLocation contents:[NSData data] attributes:[NSDictionary dictionary]];
        self.dataFile = fopen([self.dataFileLocation cStringUsingEncoding:NSUTF8StringEncoding],"a");
    }
    return self;
}

- (void) setIsFinishedTranscoding:(BOOL)finished {
    isFinishedTranscoding = finished;
    if(finished) if(fclose(self.dataFile)) NSLog(@"Error closing file");
    self.lastAccess = [NSDate date];
}

- (NSString *) fileLocation {
    self.lastAccess = [NSDate date];
    return dataFileLocation;
}


- (void) dealloc {
    self.sourcePath = nil;
    
    NSFileManager *filemgr;
    filemgr = [NSFileManager defaultManager];
    
    [filemgr removeItemAtPath: self.dataFileLocation error: NULL];
    
    [super dealloc];
}

@end
